package main

import "fmt"

/**
struct定义
*/
type student struct {
	name string
	age  int
}

/**
method就是指定调用方的函数
*/
func (p student) signIn() {
	fmt.Println(p.name, "is sign in")
}

/**
指针传递，可以改变调用者的属性
*/
func (p *student) changeNamePtr() {
	p.name = "ChangedName-" + p.name
}

/**
值传递，改变不了调用者的属性
*/
func (p student) changeNameValue() {
	p.name = "ChangedFailed" + p.name
}

func main() {
	fmt.Println(student{"Bob", 20})
	fmt.Println(student{name: "Alice", age: 10})

	fmt.Println(student{name: "Fred"})

	fmt.Println(&student{name: "Anna", age: 40})

	s := student{name: "Sean", age: 50}
	fmt.Println(s.name)

	sp := &s
	fmt.Println(sp.age)

	sp.age = 80
	fmt.Println(s.age)
	fmt.Println(sp.age)

	p := student{"John", 20}
	p.signIn()

	p.changeNameValue()
	fmt.Println(p.name)

	p.changeNamePtr()
	fmt.Println(p.name)

}
